home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 71 / MOBICLIC 71.ISO / mac / DATA / COMMUN / temp0001 / 00207_Script_GESTION_PISTE_BULLE < prev    next >
Text File  |  2004-12-05  |  16KB  |  429 lines

  1. -- DESCRIPTION --
  2.  
  3. on getBehaviorDescription me
  4.   return \
  5.     "Affichage de texte" & RETURN & RETURN & \
  6.     "Ce comportement permet d'afficher une chaεne donnΘe dans un acteur champ ou texte. " & \
  7.     "Utilisez ce comportement avec les comportements 'Info-bulle' et 'Hypertexte - Affichage de l'Θtat' qui ont besoin d'un acteur champ ou texte pour afficher leurs informations. " & \
  8.     "Ou crΘez votre propre Lingo personnalisΘ pour afficher des informations d'exΘcution telles que la position de la souris." & RETURN & RETURN & \
  9.     "Ce comportement attend des instructions Lingo. " & \
  10.     "Il n'est pas actif de lui-mΩme." & RETURN & RETURN & \
  11.     "Vous pouvez choisir entre deux types d'affichage : info-bulle et barre d'Θtat." & RETURN & RETURN & \
  12.     "Le type d'affichage 'info-bulle' entraεne le redimensionnement de l'acteur champ ou texte de maniΦre α accommoder le texte, et sa disparition lorsqu'il est vide. " & \
  13.     "Vous pouvez rΘgler le type d'affichage des info-bulles pour qu'elles apparaissent α n'importe quel endroit de la scΦne, tel que sous le curseur. " & \
  14.     "Si aucune position n'est envoyΘe α l'image-objet, celle-ci apparaεt alors dans le coin supΘrieur gauche de la scΦne. " & \
  15.     "Consultez le comportement Info-bulle pour plus d'informations." & RETURN & RETURN & \
  16.     "Pour afficher plusieurs lignes de texte, vous devrez utiliser des caractΦres de retour α la ligne pour indiquer les passages α la ligne. " & \
  17.     "Les images-objets info-bulles sortent de la scΦne lorsqu'elles ne contiennent aucun texte. " & \
  18.     "Il est conseillΘ de la placer hors de la scΦne avant son utilisation, au cas o∙ elle apparaεtrait briΦvement α l'Θcran." & RETURN & RETURN & \
  19.     "Le type d'affichage 'barre d'Θtat' apparaεt sur la scΦne de faτon permanente. " & \
  20.     "Il n'est pas redimensionnΘ et ne change pas de position. " & \
  21.     "Les informations de positionnement envoyΘes α cette image-objet ne sont pas prises en considΘration si celle-ci est rΘglΘe pour agir en tant que barre d'Θtat. " & \
  22.     "Si le texte est trop long pour apparaεtre dans l'acteur de l'image-objet, une barre de dΘfilement est affichΘe. " & \
  23.     "Il n'est pas nΘcessaire de diviser le texte α l'aide de caractΦres de retour α la ligne. " & \
  24.     "Si vous pensez qu'une barre de dΘfilement peut Ωtre nΘcessaire, vΘrifiez que l'acteur champ ou texte est suffisamment haut pour le bon fonctionnement des flΦches de dΘfilement." & RETURN & RETURN & \
  25.     "RΘglez la taille de la police ainsi que les autres caractΘristiques de l'acteur champ ou texte pour personnaliser l'apparence du message." & RETURN & RETURN & \
  26.     "N'oubliez pas de donner un nom α l'acteur champ ou texte. " & \
  27.     "Il est possible que ce comportement le vide. " & \
  28.     "Director efface automatiquement les acteurs vides sans nom." & RETURN & RETURN & \
  29.     "Types d'acteurs autorisΘs :" & RETURN & \
  30.     "champ et texte" & RETURN & RETURN & \
  31.     "ParamΦtres :" & RETURN & \
  32.     "* Type d'affichage :" & RETURN & \
  33.     "- Info-bulle (apparaεt prΦs du curseur lors du survol)" & RETURN & \
  34.     "- Barre d'Θtat (apparaεt α une position fixe de faτon permanente)" & RETURN & RETURN & \
  35.     "MΘthodes publiques :" & RETURN & \
  36.     "* DΘfinir le texte α afficher (et la position de l'image-objet)" & RETURN & RETURN & \
  37.     "Comportements associΘs :" & RETURN & \
  38.     "* Info-bulle" & RETURN & \
  39.     "* Etat de la source" & RETURN & \
  40.     "* Hypertexte - Affichage de l'Θtat"
  41. end getBehaviorDescription
  42.  
  43.  
  44. on getBehaviorTooltip me
  45.   return \
  46.     "Utilisable avec les acteurs champ ou texte." & RETURN & RETURN & \
  47.     "Attend un message provenant d'un autre comportement ou d'un gestionnaire personnalisΘ pour afficher une chaεne de caractΦres. " & \
  48.     "Ce comportement est conτu pour Ωtre utilisΘ avec les comportements 'Info-bulle' et 'Hypertexte - Affichage de l'Θtat' pour crΘer une barre d'Θtat ou une info-bulle sous le curseur."
  49. end getBehaviorTooltip
  50.  
  51.  
  52.  
  53. -- NOTES FOR DEVELOPERS --
  54.  
  55. -- COMMUNICATING WITH THE SPRITE
  56. -- To set the text of the current sprite's member, use a line similar to one of
  57. -- the following:
  58. --
  59. --    sendAllSprites (#DisplayText_SetText, theStringToDisplay)
  60. --
  61. --    sendSprite (<spriteNumber>, #DisplayText_SetText, theStringToDisplay)
  62. --
  63. --    call (#DisplayText_SetText, displayBehavior, theStringToDisplay)
  64. --
  65. -- It is fastest to call the behavior directly.  Use code similar to the
  66. -- following lines in any script that needs to communicate with this behavior
  67. -- often:
  68. --
  69. --    property displayBehavior
  70. --
  71. --    ...
  72. --    displayBehavior = []
  73. --    sendAllSprites (#DisplayText_Enroll, displayBehavior)
  74. --    ...
  75. --
  76. -- If your _Enroll call fails for some reason, displayBehavior will be an
  77. -- empty list.  Calling an empty list will not produce an error (calling an
  78. -- invalid behavior reference will).  It would, however, be wise to provide
  79. -- yourself with an authortime alert so that you can correct such a problem
  80. -- if necessary:
  81. --
  82. --    if displayBehavior.count() = 0 then
  83. --      if the runMode = "Author" then
  84. --        alert "No 'Display Text' behavior found in frame "the frame
  85. --      end if
  86. --    end if
  87. --
  88. -- Writing this sort of "defensive" code should ensure that any bugs that make
  89. -- it through to the finished product are relatively harmless.
  90.  
  91. -- ADJUSTING THE WIDTH OF THE SPRITE
  92. -- The BestRect function is called if you choose the Tooltip display type.  It
  93. -- modifies the width of the sprite to suit the longest line/paragraph of text \
  94. -- (field lines and text paragraphs are delimited by the RETURN character).
  95. --
  96. -- This function uses the charPosToLoc() function to determine the length of
  97. -- each line.  CharPosToLoc returns the position of the bottom left corner of
  98. -- the tested character: if the character tested is the final RETURN of a line,
  99. -- then the value returned is equiavalent to the bottom right of the last
  100. -- visible character in the line.
  101. --
  102. -- I initially set the width of the member to an extravagantly large value, to
  103. -- ensure that no line-wrapping should occur.
  104.  
  105.  
  106.  
  107.  
  108. -- HISTORY --
  109.  
  110. --  1 october 1998:  Written for the D7 Behaviors Palette by James Newton
  111. -- 28 October 1998:  Descriptions improved. getPDL simplified, GetTopLeft() added
  112. --  7 January 2000:  Added isOKToAttach and substituteStrings event handlers
  113. --                   and removed redundant error checking code - Karl Miller
  114. -- 13 January 2001:  Set state of member to not editable on initialize. Reset on endSprite
  115. --                   Set the locZ to maxInt - 1 to place the tooltip on top. Reset on endSprite
  116. --                   -- Kraig Mentor
  117.  
  118.  
  119. -- PROPERTIES --
  120.  
  121. property spriteNum
  122. -- error checking
  123. property getPDLError
  124. -- author-defined parameters
  125. property myDisplayType
  126. -- internal properties
  127. property mySprite
  128. property myMember
  129. property myWidthAdjust
  130. property myHeightAdjust
  131. property myOffStageLoc
  132. property myOriginalEditableState
  133. property myOriginalLocZ
  134.  
  135.  
  136. -- EVENT HANDLERS --
  137.  
  138. on beginSprite me
  139.   myDisplayType = resolve(myDisplayType)
  140.   Initialize me
  141. end beginSprite
  142.  
  143.  
  144. on endSprite me
  145.   mySprite.visible = TRUE
  146.   myMember.editable = myOriginalEditableState
  147.   mySprite.locZ =   myOriginalLocZ  
  148. end endSprite
  149.  
  150.  
  151. -- CUSTOM HANDLERS --
  152.  
  153. on resolve(prop)
  154.   case prop of
  155.     myDisplayType:
  156.       choicesList = ["barre d'Θtat (taille et position fixes)", \
  157.                      "info-bulle (taille et position dynamiques)"]
  158.       lookup = [#statusBar, #tooltip]
  159.   end case
  160.   return lookup[findPos(choicesList, prop)]
  161. end resolve
  162.  
  163. on Initialize me -- sent by beginSprite
  164.   
  165.   mySprite = sprite(me.spriteNum)
  166.   myMember = mySprite.member
  167.   myOriginalEditableState = myMember.editable
  168.   myOriginalLocZ = mySprite.locZ
  169.   myMember.editable = FALSE
  170.   
  171.   if myMember.type  = #field then
  172.     myWidthAdjust  = (myMember.margin + myMember.border) * 2
  173.     myHeightAdjust = myMember.margin + myMember.border * 2
  174.     -- no gremlins here:) 
  175.   else
  176.     myWidthAdjust  = 0
  177.     myHeightAdjust = 0
  178.   end if
  179.   myMember.text = EMPTY
  180.   
  181.   if myDisplayType = #tooltip then
  182.     myMember.boxType = #fixed
  183.     myOffStageLoc    = point (999, 999)
  184.     mySprite.loc     = myOffStageLoc
  185.   end if
  186. end Initialize
  187.  
  188.  
  189.  
  190.  
  191. on BestRect me, theString -- sent by DisplayText_SetText
  192.   -- Sets the rect of myMember to fit snugly round theString it displays
  193.   
  194.   myMember.rect = rect (0, 0, 8000, 0)
  195.   myMember.text = theString -- Needed to update myMember.rect
  196.   bestRect = myMember.rect
  197.   theLine = the number of lines of theString
  198.   theWidth = 0
  199.   checkedChars = 0
  200.   -- Determine the length of the longest line
  201.   repeat while theLine
  202.     endOfLine = offset (RETURN, theString)
  203.     if not endOfLIne then
  204.       -- Only one line remaining
  205.       endOfLine = (the number of chars of theString) + 1
  206.       myMember.text = myMember.text & RETURN
  207.     end if
  208.     checkedChars = checkedChars + endOfLine
  209.     endPoint = charPosToLoc (myMember, checkedChars)
  210.     lineWidth = endPoint[1]
  211.     if lineWidth > theWidth then
  212.       theWidth = lineWidth
  213.     end if
  214.     delete char 1 to endOfLine of theString
  215.     theLine = theLine - 1
  216.   end repeat
  217.   -- Determine the height of the text
  218.   lastChar    = myMember.char.count
  219.   lastCharLoc = charPosToLoc (myMember, lastChar)
  220.   theHeight   = lastCharLoc[2]
  221.   -- 
  222.   bestRect[3] = theWidth + 3
  223.   bestRect[4] = theHeight + 3
  224.   return bestRect
  225. end BestRect
  226.  
  227.  
  228. on GetTopLeft me, theLoc, theAlignment, memberRect
  229.   case theAlignment of
  230.     #bottomCenter: return theLoc - [memberRect.width / 2, memberRect.height]
  231.     #bottomRight:  return theLoc - [memberRect.width,     memberRect.height]
  232.     #bottomLeft:   return theLoc - [0, memberRect.height]
  233.     #center:       return theLoc - [memberRect.width / 2, memberRect.height / 2]
  234.     #topCenter:    return theLoc - [memberRect.width / 2, 0]
  235.     #topRight:     return theLoc - [memberRect.width, 0]
  236.     otherwise -- treat as #topLeft
  237.       return theLoc
  238.   end case
  239. end GetTopLeft
  240.  
  241.  
  242.  
  243. -- INTER-SPRITE COMMUNICATION (response to #sendSprite, #sendAllSprites) --
  244.  
  245. on DisplayText_Enroll me, enrollList
  246.   -- sent by objects which need to call this specific behavior
  247.   if ilk (enrollList) <> #list then return me
  248.   if not enrollList.count() then
  249.     enrollList.append(me)
  250.   else
  251.     -- the calling behavior has already found a candidate
  252.   end if
  253.   return enrollList
  254. end DisplayText_Enroll
  255.  
  256.  
  257. on DisplayText_SetText me, theString, theLoc, theAlignment
  258.   -- called by other objects
  259.   -- Sets the text of myMember to theString and shows mySprite 
  260.   -- as near to theLoc as possible (if myDisplayType is #tooltip)
  261.   --
  262.   -- theAlignment can take any of the following values: 
  263.   -- #bottomCenter|#bottomRight|#bottomLeft|#center|#topCenter|#topRight|#topLeft
  264.   -- This determines which point of the current sprite is to appear at theLoc
  265.   
  266.   -- Error check
  267.   if not stringP (theString) then
  268.     ErrorAlert (me, #invalidString, theString)
  269.     theString = string (theString)
  270.   else
  271.     case ilk (theLoc) of
  272.       #void, #point: -- nothing
  273.       otherwise
  274.         ErrorAlert (me, #invalidPoint, theLoc)
  275.         theLoc = point (0, 0)
  276.     end case
  277.   end if
  278.   -- End of error check
  279.   
  280.   if theString = EMPTY and myDisplayType = #tooltip then
  281.     mySprite.loc = myOffStageLoc
  282.     mySprite.locZ =   myOriginalLocZ  
  283.   else
  284.     
  285.     
  286.     myMember.text = theString
  287.     if myDisplayType = #tooltip then
  288.       memberRect = BestRect (me, theString)
  289.       myMember.rect = memberRect 
  290.     else
  291.       memberRect = myMember.rect 
  292.     end if
  293.     memberRect = memberRect + [0, 0, myWidthAdjust, myHeightAdjust]
  294.     if myDisplayType = #tooltip then
  295.       mySprite.locZ = the maxInteger 
  296.       
  297.       if ilk (theLoc) <> #point then
  298.         theLoc = point (0, 0)
  299.       end if
  300.       theLoc = GetTopLeft (me, theLoc, theAlignment, memberRect)
  301.       -- Ensure sprite is fully visible on stage
  302.       stageWidth = (the activeWindow).rect.right - (the activeWindow).rect.left
  303.       stageHeight= (the activeWindow).rect.bottom - (the activeWindow).rect.top
  304.       maxH = stageWidth  - memberRect.width
  305.       maxV = stageHeight - memberRect.height
  306.       theLoc[1] = max (0, min (theLoc[1], maxH))
  307.       theLoc[2] = max (0, min (theLoc[2], maxV))
  308.       
  309.       theLoc = theLoc + myMember.regPoint
  310.       mySprite.loc = theLoc
  311.     else
  312.       lastChar   = theString.char.count
  313.       textHeight = charPosToLoc (myMember, lastChar)[2]
  314.       if textHeight > mySprite.height then
  315.         myMember.boxType = #scroll
  316.       else
  317.         myMember.boxType = #fixed
  318.       end if
  319.     end if
  320.   end if
  321. end DisplayText_SetText
  322.  
  323.  
  324. on DisplayText_GetReference me
  325.   return me
  326. end DisplayText_GetReference
  327.  
  328.  
  329.  
  330. -- ERROR CHECKING --
  331.  
  332. on ErrorAlert me, theError, data
  333.   -- Determine the behavior's name
  334.   behaviorName = string (me)
  335.   delete word 1 of behaviorName
  336.   delete the last word of behaviorName
  337.   delete the last word of behaviorName
  338.   
  339.   case theError of
  340.     #invalidString:
  341.       if the runMode = "Author" then
  342.         message = substituteStrings(me, \
  343. "Erreur de comportement : Image ^0, Image-objet ^1" & RETURN & \
  344.     "Comportement ^2" & RETURN & RETURN & \
  345.     "Le gestionnaire 'DisplayText_SetText' ne peut pas traiter l'objet suivant comme une chaεne :" & RETURN & \
  346.     "^3", \
  347. ["^0": the frame, "^1": me.spriteNum, "^2": behaviorName, "^3": data])
  348.         alert message
  349.       end if
  350.     #invalidPoint:
  351.       if the runMode = "Author" then
  352.         message = substituteStrings(me, \
  353. "Erreur de comportement : Image ^0, Image-objet ^1" & RETURN & \
  354.     "Comportement ^2" & RETURN & RETURN & \
  355.     "Le gestionnaire 'DisplayText_SetText' ne peut pas traiter l'objet suivant comme un point :" & RETURN & RETURN & \
  356.     "^3", \
  357. ["^0": the frame, "^1": me.spriteNum, "^2": behaviorName, "^3": data])
  358.       end if
  359.   end case
  360. end ErrorAlert
  361.  
  362.  
  363.  
  364. on substituteStrings(me, parentString, childStringList) --------------
  365.   -- 
  366.   -- * Modifies parentString so that the strings which appear as
  367.   --   properties in childStringList are replaced by the values
  368.   --   associated with those properties.
  369.   --
  370.   -- <childStringList> has the format ["^1": "replacement string"]
  371.   --------------------------------------------------------------------
  372.   
  373.   i = childStringList.count()
  374.   repeat while i
  375.     tempString = ""
  376.     dummyString  = childStringList.getPropAt(i)
  377.     replacement  = childStringList[i]
  378.     lengthAdjust = dummyString.char.count - 1
  379.     repeat while TRUE
  380.       position = offset(dummyString, parentString)
  381.       if not position then
  382.         parentString = tempString&parentString
  383.         exit repeat
  384.       else
  385.         if position <> 1 then
  386.           tempString = tempString&parentString.char[1..position - 1]
  387.         end if
  388.         tempString = tempString&replacement
  389.         delete parentString.char[1..position + lengthAdjust]
  390.       end if
  391.     end repeat
  392.     i = i - 1
  393.   end repeat
  394.   
  395.   return parentString
  396. end substituteStrings 
  397.  
  398.  
  399.  
  400. -- AUTHOR-DEFINED PARAMETERS --
  401.  
  402. on isOKToAttach (me, aSpriteType, aSpriteNum)
  403.   case aSpriteType of
  404.     #graphic:
  405.       return getPos([#field, #text], sprite(aSpriteNum).member.type) <> 0
  406.     #script:
  407.       return FALSE
  408.    end case
  409. end isOKToAttach
  410.  
  411.  
  412.  
  413. on getPropertyDescriptionList me
  414.   
  415.   if not the currentSpriteNum then exit
  416.   
  417.   return \
  418. [ \
  419.  #myDisplayType: \
  420.  [ \
  421.   #comment: "Affichage de texte se comporte en tant que :", \
  422.   #format:  #string, \
  423.   #default: "barre d'Θtat (taille et position fixes)", \
  424.   #range: ["barre d'Θtat (taille et position fixes)", \
  425.    "info-bulle (taille et position dynamiques)"] \
  426.  ] \
  427. ]
  428. end getPropertyDescriptionList
  429.